<?php  
header("content-type:text/html;charset=utf-8");  
if (!isset($_SESSION)) {  
    session_start();  
}  
if (!isset($_SESSION['userName'])) {  
    header("location:login.php");  
} else {  
    $id = $_REQUEST['id']; 
    require_once 'dbconfig.php';  

    // 首先删除 score 表中对应的成绩记录  
    $deleteScoresSql = "delete from score where studentId = (select studentId from student where id = $id)";  
    $deleteScoresResult = mysql_query($deleteScoresSql, $conn);  
      
    if ($deleteScoresResult) {  
        // 接着删除 student 表中的学生记录  
        $deleteStudentSql = "delete from student where id = $id";  
        $deleteStudentResult = mysql_query($deleteStudentSql, $conn);  
          
        if ($deleteStudentResult) {  
            echo "<script>alert('删除成功!');parent.location.href='index.php';</script>";  
        } else {  
            echo "<script>alert('删除学生信息失败!');parent.location.href='index.php';</script>";  
        }  
    } else {  
        echo "<script>alert('删除成绩信息失败!');parent.location.href='index.php';</script>";  
    }  
      
    // 关闭数据库连接  
    mysql_close($conn);  
}  
?>